#include <p18f24k22.h>
#include "rfid.h"

void rfid_init()
{
	//Stupid ANSEL stuff
	ANSELA &= 0x00;
	ANSELB &= 0x00;
	ANSELC &= 0x00;
	//RFID Init
	TRISB |= 0x20;
	TRISB &= ~0x10;
	LATB &= ~0x10;
	INTCONbits.RBIE = 1;		// Port B interupt enabled
	INTCON2bits.RBIP = 0;		// Port B interrupt low priority
	IOCB = 0x20;
	//UART2 Init
	TXSTA2bits.BRGH = 1;
	SPBRG2 = 0x81;				// Baud number 129
	TRISB |= 0xC0;
	RCSTA2bits.SPEN = 1;
	TXSTA2bits.SYNC = 0;
	RCSTA2bits.CREN = 1;
	//Timer2 Init
	T2CON=0b00000010;  			// Setting up timer2 bits
	PR2=0xFF;					// Setting the Period register
	IPR1bits.TMR2IP = 0;		// Setting timer2 as low priority
	PIE1bits.TMR2IE = 1;		// Enabling timer2 interrupt flag 
}


